@page "/missions"
@using Unity.ClusterDisplay.MissionControl.MissionControl;

@{
    var isRunning = MissionControlStatus.State != State.Idle;
    var loadTitle = isRunning ? "Cannot load while running." : "";
}

<PageTitle>Snapshots</PageTitle>

<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.SpaceBetween" AlignItems="AlignItems.Center" class="page-title-row">
<RadzenText Text="Snapshots" TextStyle="TextStyle.DisplayH4" />
    <RadzenButton Click=@DeleteSelectedSnapshots Text="Delete" Icon="delete" ButtonStyle="ButtonStyle.Light"
                  Disabled=@(!HasSelection) />
</RadzenStack>

<RadzenDataGrid @ref="m_MissionsGrid" Data=@MissionsService.Collection.Values
                AllowMultiColumnSorting="true" ShowMultiColumnSortingIndex="true" AllowSorting="true"
                AllowRowSelectOnRowClick="false" SelectionMode="DataGridSelectionMode.Multiple" @bind-Value="@m_SelectedSnapshots">
    <Columns>
        <RadzenDataGridColumn TItem="SavedMissionSummary" Width="60px" Sortable="false" Filterable="false">
            <HeaderTemplate>
                <RadzenCheckBox TriState="false" TValue="bool"
                                Value="@HasSelection"
                                Change=@SelectAllOrNone />
            </HeaderTemplate>
            <Template Context="mission">
                <RadzenCheckBox TriState="false" Value="@(m_SelectedSnapshots.Contains(mission))"
                                TValue="bool" Change=@(args => m_MissionsGrid.SelectRow(mission)) />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="SavedMissionSummary" Title="Name" Property="Description.Name" />
        <RadzenDataGridColumn TItem="SavedMissionSummary" Title="Description" Property="Description.Details" />
        <RadzenDataGridColumn TItem="SavedMissionSummary" Title="Save time" Property="SaveTime"/>
        <RadzenDataGridColumn TItem="SavedMissionSummary" Title="Asset" Sortable="false">
            <Template Context="mission">
                @if (AssetsService.Collection.TryGetValue(mission.AssetId, out var asset))
                {
                    <span>@asset.Name</span>
                }
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="SavedMissionSummary" Width="130px">
            <Template Context="mission">
                <RadzenButton Variant="Variant.Text" Click=@(() => Load(mission)) Text="Load" ButtonStyle="ButtonStyle.Info" />
                <RadzenButton Icon="delete" Class="m-1 data-grid-icon" Click=@(() => Delete(mission)) ButtonStyle="ButtonStyle.Light" />
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

